
function RefreshJob(jobUri, statusDisplay, contentPanel) {
  RefreshJob._super.call(this, BasePath.get() + "/livcos.org/web/job/refresh.job");
  this.data = "";
  this.addData("job", jobUri);
  this.errorMessage = "Could not update changes!";
  this.contentPanel = contentPanel;
}
Object.extend("RefreshJob", "Job");

RefreshJob.prototype.onSuccess = function() {
	if (this.onRefresh)
		this.onRefresh();
  else
    this.mergeResponse();
}

RefreshJob.prototype.onFailed = function() {
	if (this.onRefresh)
		this.onRefresh();
  RefreshJob._super.prototype.onFailed.call(this);
}

RefreshJob.prototype.onTimeout = function() {
	if (this.onRefresh)
		this.onRefresh();
  LivCosResource.prototype.onTimeout.call(this);
}

RefreshJob.prototype.mergeResponse = function() {
	if (!this.dom) {
    this.statusLog.showError("Invalid DOM for successfull refresh response!");
    return false;
	}
	this.statusLog.show("merging new data...");
	this.contentPanel.merge(this.dom.getElementsByTagName("div")[0]);
	this.statusLog.show("refresh successfull");
	return true;
}

RefreshJob.prototype.execute = function() {
	this.statusLog.show("refresh data...");
  var data = "view=" + encodeURIComponent(this.contentPanel.getViewUri());
	this.send(data + "&" + this.data);
}

function refresh(jobUri, params) {
	var doc = Doc();
	var job = new RefreshJob(jobUri, doc.doc.statusDisplay, doc.contentPanel);
	var i = 0;
	for (var param in params) {
		job.addData("name_" + (++i), param);
		job.addData("value_" + i, params[param]);
	}
	job.execute();
}